/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on 06/11/2011, 10:59:03
 */
package br.ufc.si.tcc.qmusic.gui;

import br.ufc.si.tcc.qmusic.automatoImp.AutomatoImp;
import br.ufc.si.tcc.qmusic.automatoImp.Reconhecedor;
import br.ufc.si.tcc.qmusic.interfaces.IAcorde;
import br.ufc.si.tcc.qmusic.model.Acorde;
import br.ufc.si.tcc.qmusic.model.Nota;
import br.ufc.si.tcc.qmusic.model.Tetrade;
import br.ufc.si.tcc.qmusic.model.Triade;
import br.ufc.si.tcc.qmusic.properties.Properties;
import br.ufc.si.tcc.qmusic.util.MidiData;
import br.ufc.si.tcc.qmusic.util.UtilQMusic;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.sound.midi.*;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import jm.JMC;
import jm.constants.ProgramChanges;
import jm.midi.event.NoteOn;
import jm.music.data.Note;
import jm.music.data.Part;
import jm.music.data.Phrase;
import jm.music.data.Score;
import jm.util.Read;
import jm.util.View;
import jm.util.Write;

/**
 *
 * @author Lucas Ismaily
 */
public class GUI extends javax.swing.JFrame implements JMC {

    Score score;
    Sequence musicMidi;
    Sequencer player;
    ArrayList<Instrument> instruments;
    ArrayList<Nota> notes;
    AutomatoImp automato;
    File file;
    int volume;
    int instrumento;
    Instrument instrumentoSelecionado;

    /**
     * Creates new form GUI
     */
    public GUI() {

        initComponents();

        musicMidi = null;
        score = null;
        player = null;
        notes = null;
        instruments = null;
        instrumento = -1;
        automato = new AutomatoImp();
        initPanel();
        setEscolhaDisponivel(false);



    }

    public void initPanel() {

        jPanel_AnalisarMusica.setVisible(true);
        jPanel_CriarMusica.setVisible(false);
        GrupoBotoesDetalhamento.add(jRadioButton_modo_avancado);
        GrupoBotoesDetalhamento.add(jRadioButton_modo_padrao);
        GrupoBotoesDetalhamento.add(jRadioButton_mostrar_todas_notas);
        jRadioButton_modo_avancado.setSelected(true);
        //jButton_cancelar_result.setEnabled(false);
    }

    private void iniTiposReconhecimento() {
        jComboBox_tipoEscolha.removeAllItems();
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TODAS_TRIADES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TODAS_TETRADES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TRIADES_TETRADES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TRIADES_MENORES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TRIADES_MAIORES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TRIADES_AUMENTADA);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_TRIADES_DIMINUTA);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_APENAS_TETRADES_MAIORES);
        jComboBox_tipoEscolha.addItem(Properties.RECONHECER_APENAS_TETRADES_MENORES);
    }

    private void setEscolhaDisponivel(boolean disponivel) {

        jRadioButton_modo_avancado.setEnabled(disponivel);
        jRadioButton_modo_padrao.setEnabled(disponivel);
        jRadioButton_mostrar_todas_notas.setEnabled(disponivel);
        jComboBox_tipoEscolha.setEnabled(disponivel);
        jComboBox_instrument.setEnabled(disponivel);
        jButton_reconhecer.setEnabled(disponivel);
        //jButton_cancelar_result.setEnabled(!disponivel);

    }

    private void mensagemNaoPodeFormarTriade(Triade triade) {

       
            jTextArea_result.append("\n" + triade.getTipo() + " from the note ["
                    + triade.getTonica().getNota() + "]");
        
    }

    private void mensagemNaoPodeFormarTetrade(Tetrade tetrade) {

       
            jTextArea_result.append("\n" + tetrade.getTipo() + " from the note ["
                    + tetrade.getTriade().getTonica().getNota() + "]");
                   
                   
       
    }

    private void mensagemNaoPodeFormarAcorde(IAcorde acorde) {

       jTextArea_result.append("\n" + acorde.getTipo() + " from the note ["
                    + acorde.getTriade().getTonica().getNota() + "]");

    }

    private boolean setNotes() {

        if (score == null) {
            return false;
        }

        Part[] parts = score.getPartArray();
        System.out.println("Instrumento: ");
        Note[] notas = null;
        notes = new ArrayList<Nota>();
        for (int i = 0; i < parts.length; i++) {
            if (parts[i].getPhraseArray().length == 0 || (parts[i].getInstrument() != instrumentoSelecionado.getPatch().getProgram())) {
                continue;
            }

            System.out.println(" " + parts[i].getInstrument());
            Phrase[] pharase = parts[i].getPhraseArray();
            System.out.println("Tempo Part [" + i + "] " + parts[i].getTempo());
            for (int k = 0; k < pharase.length; k++) {
                if (pharase[k].getNoteArray().length == 0) {
                    continue;
                }
                notas = pharase[k].getNoteArray();
                System.out.println("tempo do Pharase[" + k + "} = " + pharase[k].getStartTime());
                for (int j = 0; j < notas.length; j++) {
                    Note n = notas[j];
                    Nota nota = new Nota();
                    //não é nota, é uma pausa, as notas tem pitch de 0 a 127
                    if (notas[j].getNote().equalsIgnoreCase("")
                            || (notas[j].getPitch() < 0 || notas[j].getPitch() > 127)) {

                        continue;
                    }
                    System.out.println("Pharase = " + k + " nota = " + n.getNote() + " tempo " + n.getMyPhrase().getNoteStartTime(j) + n.getOffset());
                    nota.setNota(n.getNote());
                    nota.setDuracao(n.getDuration());
                    nota.setDeltaTimeInicial(n.getMyPhrase().getNoteStartTime(j) + n.getOffset());
                    nota.setVolume(n.getDynamic());
                    notes.add(nota);
                }
            }
        }
        System.out.println("numero de notas antes de ordenar = " + notes.size());
        notes = UtilQMusic.eliminarDecalagem(notes);
        for (Nota n : notes) {
            System.out.println("nota = " + n.getNota() + " tempo " + n.getDeltaTimeInicial());
        }
        System.out.println("Depois de ordenar numero de notas " + notes.size());
        return true;
    }
    /*
     * private boolean setNotes2() {
     *
     * if (score == null) { return false; } Part[] parts = score.getPartArray();
     * System.out.println("Instrumento: "); Note[] notas = null; notes = new
     * ArrayList<Nota>(); for (int i = 0; i < parts.length; i++) { if
     * (parts[i].getPhraseArray().length == 0 || (parts[i].getInstrument() !=
     * instrumentoSelecionado.getPatch().getProgram())) { continue; }
     * System.out.println(" " + parts[i].getInstrument()); Phrase[] pharase =
     * parts[i].getPhraseArray(); for (int k = 0; k < pharase.length; k++) { if
     * (pharase[k].getNoteArray().length == 0) { continue; } notas =
     * pharase[k].getNoteArray(); System.out.println("Notas e suas durações");
     * for (int j = 0; j < notas.length; j++) { Note n = notas[j]; Nota nota =
     * new Nota(); if (notas[j].getNote().equalsIgnoreCase("")) { continue; }
     * System.out.println("" + n.getNote() + " " +
     * n.getMyPhrase().getNoteStartTime(j)); nota.setNota(n.getNote());
     * nota.setDuracao(n.getDuration());
     * nota.setDeltaTimeInicial(n.getMyPhrase().getNoteStartTime(j));
     * nota.setVolume(n.getDynamic()); notes.add(nota); } } } notes =
     * UtilQMusic.eliminarDecalagem(notes); return true; }
     */

    private void reconhecerTriadesTetrades(String tipoEscolha, String tipoReconhecimento) {
        List<IAcorde> triades = new AutomatoImp().reconhecerTriadesTetrades((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));

        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        jTextArea_result.append("[Recognize: " + tipoEscolha + " ]\n");
        jTextArea_result.append("[" + tipoReconhecimento + " ] \n");
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        
         if(!UtilQMusic.temAcordeValido(triades)){
            jTextArea_result.append("No Sevenths and No Triads\n");
            return;
        }
        
        
        if (triades == null || triades.isEmpty()) {
            jTextArea_result.append("Erro: sorry, we can do reconnaissance operation\n");

        } else {
            for (IAcorde t : triades) {
                if (t instanceof Triade) {
                    //Se não for enamornica ou não se pode formar, exibimos a triade com suas notas
                    if (!t.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)
                            && !t.getTipo().equalsIgnoreCase(Properties.NAO_FORMOU_TRIADE)) {
                        if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                            jTextArea_result.append("\n" + t.getTipo() + " of " + t.getTonica().getNota() + " -->"
                                    + "Formed form the notes [Root = " + t.getTonica().getNota() + ", "
                                    + "Third = " + t.getTerca().getNota() + ", "
                                    + "Fifth = " + t.getQuinta().getNota() + "] ");
                        } else {
                            jTextArea_result.append(" " + t.getNotacaoABC());
                        }
                    } else if (t.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)) {
                        //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                        if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                            jTextArea_result.append("\n" + t.getTipo() + " of " + t.getTonica().getNota() + "."
                                    + "To comply with music theory, we suggest the following changes: ");

                            Nota tercaComp = t.getEnarmonicaTerca();
                            Nota quintaComp = t.getEnarmonicaQuinta();

                            if (tercaComp != null) {
                                jTextArea_result.append(" [Third] --> change " + t.getTerca().getNota() + " for " + tercaComp.getNota());
                            }
                            if (quintaComp != null) {
                                jTextArea_result.append(" [Fifth] --> change " + t.getQuinta().getNota() + " for " + quintaComp.getNota());
                            }
                        } else {
                            jTextArea_result.append(" " + t.getNotacaoABC());
                        }

                    }
                } else if (t instanceof Tetrade) {
                    //Se não for enamornica ou não se pode formar, exibimos a tetrade com suas notas
                    if (!t.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)
                            && !t.getTipo().equalsIgnoreCase(Properties.NAO_FORMOU_TRIADE_NEM_TETRADE)) {
                        if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                            jTextArea_result.append("\n" + t.getTipo() + " of " + t.getTriade().getTonica().getNota() + " -->"
                                    + "Formed from the notes [Root = " + t.getTriade().getTonica().getNota() + ", "
                                    + "Third = " + t.getTriade().getTerca().getNota() + ", "
                                    + "Fifth = " + t.getTriade().getQuinta().getNota() + ", "
                                    + "Seventh = " + t.getSetima().getNota() + "] ");
                        } else {
                            jTextArea_result.append("\n" + t.getNotacaoABC());
                        }
                    } else if (t.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)) {
                        //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                        if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                            jTextArea_result.append("\n" + t.getTipo() + " of " + t.getTriade().getTonica().getNota() + "."
                                    + "To comply with music theory, we suggest the following changes: ");

                            Nota tercaComp = t.getTriade().getEnarmonicaTerca();
                            Nota quintaComp = t.getTriade().getEnarmonicaQuinta();
                            Nota setimaComp = t.getSetimaEnarmonica();

                            if (tercaComp != null) {
                                jTextArea_result.append(" [Third] --> change " + t.getTriade().getTerca().getNota() + " for " + tercaComp.getNota());
                            }
                            if (quintaComp != null) {
                                jTextArea_result.append(" [Fifth] --> change " + t.getTriade().getQuinta().getNota() + " for " + quintaComp.getNota());
                            }
                            if (setimaComp != null) {
                                jTextArea_result.append(" [Seventh] --> change " + t.getSetima().getNota() + " for " + setimaComp.getNota());
                            }
                        } else {
                            jTextArea_result.append("\n" + t.getNotacaoABC());
                        }
                    } else {
                        if (Properties.RECONHECER_MODO_EXIBIR_TUDO.equalsIgnoreCase(tipoReconhecimento)) {
                           jTextArea_result.append("\n" + t.getTipo() + " from the note ["
                    + t.getTriade().getTonica().getNota() + "]");
                        }
                    }

                }

            }
        }
    }

    private void reconherTodasTetrades(String tipoEscolha, String tipoReconhecimento) {

        List<Nota> notas = notes;
        notas = UtilQMusic.ConvertNotasToNotacaCompleta(notas);
        List<Tetrade> tetrades = automato.reconhecerTodasTetrades((ArrayList) notas);
        
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        jTextArea_result.append("[Recognize: " + tipoEscolha + " ]\n");
        jTextArea_result.append("[" + tipoReconhecimento + " ] \n");
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");

        if(!UtilQMusic.temTetradeValida(tetrades)){
            jTextArea_result.append("No Sevenths\n");
            return;
        }
        
        if (tetrades == null || tetrades.isEmpty()) {
            jTextArea_result.append("Erro: sorry, we can do reconnaissance operation\n");

        } else {
            for (Tetrade tetrade : tetrades) {

                //Se não for enamornica ou não se pode formar, exibimos a tetrade com suas notas
                if (!tetrade.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)
                        && !tetrade.getTipo().equalsIgnoreCase(Properties.NAO_FORMOU_TETRADE)) {
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + tetrade.getTipo() + " of " + tetrade.getTriade().getTonica().getNota() + " -->"
                                + "Formed from the notes [Root = " + tetrade.getTriade().getTonica().getNota() + ", "
                                + "Third = " + tetrade.getTriade().getTerca().getNota() + ", "
                                + "Fifth = " + tetrade.getTriade().getQuinta().getNota() + ", "
                                + "Seventh = " + tetrade.getSetima().getNota() + "] ");
                    } else {
                        jTextArea_result.append("\n" + tetrade.getNotacaoABC());
                    }
                } else if (tetrade.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)) {
                    //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + tetrade.getTipo() + " of " + tetrade.getTriade().getTonica().getNota() + "."
                                + "To comply with music theory, we suggest the following changes: ");

                        Nota tercaComp = tetrade.getTriade().getEnarmonicaTerca();
                        Nota quintaComp = tetrade.getTriade().getEnarmonicaQuinta();
                        Nota setimaComp = tetrade.getSetimaEnarmonica();

                        if (tercaComp != null) {
                            jTextArea_result.append(" [Third] --> change " + tetrade.getTriade().getTerca().getNota() + " for " + tercaComp.getNota());
                        }
                        if (quintaComp != null) {
                            jTextArea_result.append(" [Fifth] --> change " + tetrade.getTriade().getQuinta().getNota() + " for " + quintaComp.getNota());
                        }
                        if (setimaComp != null) {
                            jTextArea_result.append(" [Seventh] --> change " + tetrade.getSetima().getNota() + " for " + setimaComp.getNota());
                        }
                    } else {
                        jTextArea_result.append("\n" + tetrade.getNotacaoABC());
                    }
                } else {
                    //Caso contrário exibimos que não podemos forma tétrades a apartir da nota em questão como tônica
                    if (Properties.RECONHECER_MODO_EXIBIR_TUDO.equalsIgnoreCase(tipoReconhecimento)) {
                       mensagemNaoPodeFormarTetrade(tetrade);
                    }
                }


            }
        }
    }

    private void reconherTodasTriades(String tipoEscolha, String tipoReconhecimento) {

        List<Triade> triades = automato.reconhecerTodasTriades((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
 

        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        jTextArea_result.append("[Recognize: " + tipoEscolha + " ]\n");
        jTextArea_result.append("[" + tipoReconhecimento + " ] \n");
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        
        if(!UtilQMusic.temTriadeValida(triades)){
            jTextArea_result.append("No Triads\n");
            return;
        }
        
        
        if (triades == null || triades.isEmpty()) {
            jTextArea_result.append("Erro: sorry, we can do reconnaissance operation\n");

        } else {
            for (Triade triade : triades) {

                //Se não for enamornica ou não se pode formar, exibimos a triade com suas notas
                if (!triade.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)
                        && !triade.getTipo().equalsIgnoreCase(Properties.NAO_FORMOU_TRIADE)) {
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + triade.getTipo() + " of " + triade.getTonica().getNota() + " -->"
                                + "Formed from the notes [Root = " + triade.getTonica().getNota() + ", "
                                + "Third = " + triade.getTerca().getNota() + ", "
                                + "Fifth = " + triade.getQuinta().getNota() + "] ");
                    } else {
                        jTextArea_result.append(" " + triade.getNotacaoABC());
                    }
                } else if (triade.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)) {
                    //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + triade.getTipo() + " of " + triade.getTonica().getNota() + "."
                                + "To comply with music theory, we suggest the following changes: ");

                        Nota tercaComp = triade.getEnarmonicaTerca();
                        Nota quintaComp = triade.getEnarmonicaQuinta();

                        if (tercaComp != null) {
                            jTextArea_result.append(" [Third] --> change " + triade.getTerca().getNota() + " for " + tercaComp.getNota());
                        }
                        if (quintaComp != null) {
                            jTextArea_result.append(" [Fifth] --> change " + triade.getQuinta().getNota() + " for " + quintaComp.getNota());
                        }
                    } else {
                        jTextArea_result.append("\n" + triade.getNotacaoABC());
                    }

                } else {
                    //Caso contrário exibimos que não podemos forma tétrades a apartir da nota em questão como tônica
                    if (Properties.RECONHECER_MODO_EXIBIR_TUDO.equalsIgnoreCase(tipoReconhecimento)) {
                       mensagemNaoPodeFormarTriade(triade);
                    }
                }


            }
        }
    }

    //Fazer checagem de notas enarmonicas com os intervalos
    private void reconherTriades(String tipoTriade, String tipoReconhecimento) {

        int i = 0;
        List<Triade> triades = null;
        if (tipoTriade.equals(Properties.TRIADE_AUMENTADA)) {
            triades = automato.reconhecerTriadesAumentada((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else if (tipoTriade.equals(Properties.TRIADE_DIMINUTA)) {
            triades = automato.reconhecerTriadesDiminuta((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else if (tipoTriade.equals(Properties.TRIADE_MAIOR)) {
            triades = automato.reconhecerTriadesMaiores((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else if (tipoTriade.equals(Properties.TRIADE_MENOR)) {
            triades = automato.reconhecerTriadesMenores((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else {
            jTextArea_result.append("\n Error: option of recognize was chosen wrong");
            return;
        }
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        jTextArea_result.append("[Recognize: " + tipoTriade + " ]\n");
        jTextArea_result.append("[" + tipoReconhecimento + " ] \n");
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");

         if(!UtilQMusic.temTriadeValida(triades)){
            jTextArea_result.append("No " + tipoTriade + "\n");
            return;
        }
         
        if (triades == null || triades.isEmpty()) {
            jTextArea_result.append("Erro: sorry, we can do reconnaissance operation\n");

        } else {

            for (Triade triade : triades) {

                //Se não for enamornica e for igual ao tipo buscado exibimos as triade de acordo com o modo de exibicao
                if (!triade.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)
                        && triade.getTipo().equalsIgnoreCase(tipoTriade)) {

                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + triade.getTipo() + " from " + triade.getTonica().getNota() + " -->"
                                + "Formed from the notes [Root = " + triade.getTonica().getNota() + ", "
                                + "Third = " + triade.getTerca().getNota() + ", "
                                + "Fifth = " + triade.getQuinta().getNota() + "] ");
                    } else {
                        jTextArea_result.append(" " + triade.getNotacaoABC());
                    }
                } else if (triade.getTipo().equalsIgnoreCase(Properties.TRIADE_ENARMONICA)) {
                    //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + triade.getTipo() + " from " + triade.getTonica().getNota() + "."
                                + "To comply with music theory, we suggest the following changes: ");

                        Nota tercaComp = triade.getEnarmonicaTerca();
                        Nota quintaComp = triade.getEnarmonicaQuinta();

                        if (tercaComp != null) {
                            jTextArea_result.append(" [Third] --> change " + triade.getTerca().getNota() + " for " + tercaComp.getNota());
                        }
                        if (quintaComp != null) {
                            jTextArea_result.append(" [Fifth] --> change " + triade.getQuinta().getNota() + " for " + quintaComp.getNota());
                        }
                    } else {
                        jTextArea_result.append("\n" + triade.getNotacaoABC());
                    }

                } else {
                    //Caso contrário exibimos que não podemos forma tétrades a apartir da nota em questão como tônica
                    if (Properties.RECONHECER_MODO_EXIBIR_TUDO.equalsIgnoreCase(tipoReconhecimento)) {
                        mensagemNaoPodeFormarTriade(triade);
                    }
                }


            }
        }
    }

    private void reconherTetrades(String tipoEscolha, String tipoReconhecimento) {

        List<Tetrade> tetrades = null;
        if (tipoEscolha.equals(Properties.RECONHECER_APENAS_TETRADES_MAIORES)) {
            tetrades = automato.reconhecerTetradesMaiores((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else if (tipoEscolha.equals(Properties.RECONHECER_APENAS_TETRADES_MENORES)) {
            tetrades = automato.reconhecerTetradesMenores((ArrayList) UtilQMusic.ConvertNotasToNotacaCompleta(notes));
        } else {
            jTextArea_result.append("\n Error: option of recognize was chosen wrong");
            return;
        }
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
        jTextArea_result.append("[Recognize: " + tipoEscolha + " ]\n");
        jTextArea_result.append("[" + tipoReconhecimento + " ] \n");
        jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");

        if(!UtilQMusic.temTetradeValida(tetrades)){
            jTextArea_result.append("No Sevenths\n");
            return;
        }
        
        if (tetrades == null || tetrades.isEmpty()) {
            jTextArea_result.append("Erro: sorry, we can do reconnaissance operation\n");

        } else {
            for (Tetrade tetrade : tetrades) {

                //Se não for enamornica e for igual ao tipo buscado exibimos as triade de acordo com o modo de exibicao
                if (!tetrade.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)
                        && tetrade.getTipo().equalsIgnoreCase(tipoEscolha)) {

                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + tetrade.getTipo() + " of " + tetrade.getTriade().getTonica().getNota() + " -->"
                                + "formed from notes  [Root = " + tetrade.getTriade().getTonica().getNota() + ", "
                                + "Third = " + tetrade.getTriade().getTerca().getNota() + ", "
                                + "Fifth = " + tetrade.getTriade().getQuinta().getNota() + ", "
                                + "Seventh = " + tetrade.getSetima().getNota() + "] ");
                    } else {
                        jTextArea_result.append("\n" + tetrade.getNotacaoABC());
                    }
                } else if (tetrade.getTipo().equalsIgnoreCase(Properties.TETRADE_ENARMONICA)) {
                    //caso seja enarmonica, exibimos que ela é enarmonica e sugerimos opção de troca
                    if (!Properties.RECONHECER_MODO_PADRAO.equalsIgnoreCase(tipoReconhecimento)) {
                        jTextArea_result.append("\n" + tetrade.getTipo() + " of " + tetrade.getTriade().getTonica().getNota() + "."
                                + "To comply with music theory, we suggest the following changes: ");

                        Nota tercaComp = tetrade.getTriade().getEnarmonicaTerca();
                        Nota quintaComp = tetrade.getTriade().getEnarmonicaQuinta();
                        Nota setimaComp = tetrade.getSetimaEnarmonica();

                        if (tercaComp != null) {
                            jTextArea_result.append(" [Third] --> change " + tetrade.getTriade().getTerca().getNota() + " for " + tercaComp.getNota());
                        }
                        if (quintaComp != null) {
                            jTextArea_result.append(" [Fifth] --> change " + tetrade.getTriade().getQuinta().getNota() + " for " + quintaComp.getNota());
                        }
                        if (setimaComp != null) {
                            jTextArea_result.append(" [Seventh] --> change " + tetrade.getSetima().getNota() + " for " + setimaComp.getNota());
                        }
                    } else {
                        jTextArea_result.append("\n" + tetrade.getNotacaoABC());
                    }

                } else {
                    //Caso contrário exibimos que não podemos forma tétrades a apartir da nota em questão como tônica
                    if (Properties.RECONHECER_MODO_EXIBIR_TUDO.equalsIgnoreCase(tipoReconhecimento)) {
                       mensagemNaoPodeFormarTetrade(tetrade);
                    }
                }


            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GrupoBotoesDetalhamento = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jPanel_AnalisarMusica = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_result = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jComboBox_tipoEscolha = new javax.swing.JComboBox();
        jRadioButton_modo_padrao = new javax.swing.JRadioButton();
        jRadioButton_modo_avancado = new javax.swing.JRadioButton();
        jRadioButton_mostrar_todas_notas = new javax.swing.JRadioButton();
        jComboBox_instrument = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton_reconhecer = new javax.swing.JButton();
        jPanel_CriarMusica = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jSlider1 = new javax.swing.JSlider();
        jLabel3 = new javax.swing.JLabel();
        jRadioButton3 = new javax.swing.JRadioButton();
        jButton_deteleNotes = new javax.swing.JButton();
        jButton_acidenteBemol = new javax.swing.JButton();
        jButton_acidenteSustenido = new javax.swing.JButton();
        jButton_noteG = new javax.swing.JButton();
        jButton_noteF = new javax.swing.JButton();
        jButton_noteE = new javax.swing.JButton();
        jButton_noteD = new javax.swing.JButton();
        jButton_noteC = new javax.swing.JButton();
        jButton_noteB = new javax.swing.JButton();
        jButton_noteA = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_notes = new javax.swing.JTextArea();
        jButton6 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel_dadosArquivo = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem_abrir = new javax.swing.JMenuItem();
        jMenuItem_criarMusica = new javax.swing.JMenuItem();
        jMenuItem_analisarMusica = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem_sair = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem_help = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("QMusic");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Result"));

        jTextArea_result.setColumns(20);
        jTextArea_result.setEditable(false);
        jTextArea_result.setRows(5);
        jScrollPane1.setViewportView(jTextArea_result);

        jButton3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\clear.png")); // NOI18N
        jButton3.setText("Clear All");
        jButton3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 829, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(340, 340, 340)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addContainerGap())
        );

        jLabel4.setText("                   recognition option:");

        jComboBox_tipoEscolha.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "waiting for MIDI file" }));
        jComboBox_tipoEscolha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_tipoEscolhaActionPerformed(evt);
            }
        });

        jRadioButton_modo_padrao.setText("Standard");
        jRadioButton_modo_padrao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton_modo_padraoActionPerformed(evt);
            }
        });

        jRadioButton_modo_avancado.setText("Advanced");

        jRadioButton_mostrar_todas_notas.setText("Show All Results");
        jRadioButton_mostrar_todas_notas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton_mostrar_todas_notasActionPerformed(evt);
            }
        });

        jComboBox_instrument.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "waiting for MIDI file" }));

        jLabel5.setText("Instrument:");

        jLabel6.setText("Type Result:");

        jButton_reconhecer.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\printResult.png")); // NOI18N
        jButton_reconhecer.setText("recognize");
        jButton_reconhecer.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton_reconhecer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_reconhecerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel_AnalisarMusicaLayout = new javax.swing.GroupLayout(jPanel_AnalisarMusica);
        jPanel_AnalisarMusica.setLayout(jPanel_AnalisarMusicaLayout);
        jPanel_AnalisarMusicaLayout.setHorizontalGroup(
            jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_AnalisarMusicaLayout.createSequentialGroup()
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator2)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(10, 10, 10))
            .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBox_tipoEscolha, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox_instrument, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(51, 51, 51)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton_modo_padrao)
                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                        .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton_modo_avancado)
                            .addComponent(jRadioButton_mostrar_todas_notas))
                        .addGap(35, 35, 35)
                        .addComponent(jButton_reconhecer, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel_AnalisarMusicaLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jComboBox_instrument, jComboBox_tipoEscolha});

        jPanel_AnalisarMusicaLayout.setVerticalGroup(
            jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                        .addGap(0, 17, Short.MAX_VALUE)
                        .addComponent(jComboBox_tipoEscolha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jComboBox_instrument, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39))
                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                        .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jButton_reconhecer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                    .addComponent(jLabel6)
                                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                                        .addComponent(jRadioButton_modo_avancado, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jRadioButton_mostrar_todas_notas, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton_modo_padrao, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(20, 20, 20))
            .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                .addGroup(jPanel_AnalisarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jLabel5))
                    .addGroup(jPanel_AnalisarMusicaLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel4)))
                .addContainerGap())
        );

        jPanel_AnalisarMusicaLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jComboBox_instrument, jComboBox_tipoEscolha});

        jPanel_AnalisarMusica.setBounds(10, 120, 870, 460);
        jLayeredPane1.add(jPanel_AnalisarMusica, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Volume:");

        jLabel3.setText("duration:");

        jRadioButton3.setText("Colchea");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        jButton_deteleNotes.setText("delete notes");
        jButton_deteleNotes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_deteleNotesActionPerformed(evt);
            }
        });

        jButton_acidenteBemol.setText("Ƅ");
        jButton_acidenteBemol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_acidenteBemolActionPerformed(evt);
            }
        });

        jButton_acidenteSustenido.setText("#");
        jButton_acidenteSustenido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_acidenteSustenidoActionPerformed(evt);
            }
        });

        jButton_noteG.setText("G");
        jButton_noteG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteGActionPerformed(evt);
            }
        });

        jButton_noteF.setText("F");
        jButton_noteF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteFActionPerformed(evt);
            }
        });

        jButton_noteE.setText("E");
        jButton_noteE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteEActionPerformed(evt);
            }
        });

        jButton_noteD.setText("D");
        jButton_noteD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteDActionPerformed(evt);
            }
        });

        jButton_noteC.setText("C");
        jButton_noteC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteCActionPerformed(evt);
            }
        });

        jButton_noteB.setText("B");
        jButton_noteB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteBActionPerformed(evt);
            }
        });

        jButton_noteA.setText("A");
        jButton_noteA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_noteAActionPerformed(evt);
            }
        });

        jLabel1.setText("Choose Notes:");

        GrupoBotoesDetalhamento.add(jRadioButton1);
        jRadioButton1.setText("Whole");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        GrupoBotoesDetalhamento.add(jRadioButton2);
        jRadioButton2.setText("Seminima");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        GrupoBotoesDetalhamento.add(jRadioButton4);
        jRadioButton4.setText("Seminima");
        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton4ActionPerformed(evt);
            }
        });

        jRadioButton5.setText("Colchea");
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteA)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteB)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteC)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteD)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton_noteE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteF)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_noteG)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_acidenteSustenido)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_acidenteBemol)
                        .addGap(41, 41, 41)
                        .addComponent(jButton_deteleNotes))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton5)))
                .addContainerGap(85, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton_acidenteBemol, jButton_acidenteSustenido, jButton_noteA, jButton_noteB, jButton_noteC, jButton_noteD, jButton_noteE, jButton_noteF, jButton_noteG});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton4)
                            .addComponent(jRadioButton5))
                        .addGap(18, 18, 18))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(23, 23, 23)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_noteA, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_noteB)
                    .addComponent(jButton_noteC)
                    .addComponent(jButton_noteD)
                    .addComponent(jButton_noteE)
                    .addComponent(jButton_noteF)
                    .addComponent(jButton_noteG)
                    .addComponent(jButton_acidenteSustenido)
                    .addComponent(jButton_acidenteBemol)
                    .addComponent(jLabel1)
                    .addComponent(jButton_deteleNotes, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton_acidenteBemol, jButton_acidenteSustenido, jButton_deteleNotes, jButton_noteA, jButton_noteB, jButton_noteC, jButton_noteD, jButton_noteE, jButton_noteF, jButton_noteG});

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Result"));

        jTextArea_notes.setColumns(20);
        jTextArea_notes.setEditable(false);
        jTextArea_notes.setRows(5);
        jScrollPane2.setViewportView(jTextArea_notes);

        jButton6.setText("Create");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton8.setText("Cancel");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(312, 312, 312)
                        .addComponent(jButton6)
                        .addGap(50, 50, 50)
                        .addComponent(jButton8))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton6, jButton8});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton8)
                    .addComponent(jButton6))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel_CriarMusicaLayout = new javax.swing.GroupLayout(jPanel_CriarMusica);
        jPanel_CriarMusica.setLayout(jPanel_CriarMusicaLayout);
        jPanel_CriarMusicaLayout.setHorizontalGroup(
            jPanel_CriarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_CriarMusicaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_CriarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel_CriarMusicaLayout.setVerticalGroup(
            jPanel_CriarMusicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_CriarMusicaLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel_CriarMusica.setBounds(0, 120, 880, 460);
        jLayeredPane1.add(jPanel_CriarMusica, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\play.png")); // NOI18N
        jButton2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\stop.png")); // NOI18N
        jButton5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\mostrarNotas.png")); // NOI18N
        jButton4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel_dadosArquivo.setText("Waiting for MIDI File...");

        jButton1.setText("Abrir Imagem");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(jButton5)
                .addGap(41, 41, 41)
                .addComponent(jButton4)
                .addGap(58, 58, 58)
                .addComponent(jLabel_dadosArquivo)
                .addGap(69, 69, 69)
                .addComponent(jButton1)
                .addContainerGap(245, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton2, jButton4, jButton5});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jLabel_dadosArquivo))
                .addGap(24, 24, 24))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton2, jButton4, jButton5});

        jPanel1.setBounds(10, 10, 865, 85);
        jLayeredPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(jLayeredPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 881, 593));

        jMenu1.setText("File");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem_abrir.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\abrir.png")); // NOI18N
        jMenuItem_abrir.setText("Open MIDI file");
        jMenuItem_abrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_abrirActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem_abrir);

        jMenuItem_criarMusica.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\NovoMidi.png")); // NOI18N
        jMenuItem_criarMusica.setText("Create new music ");
        jMenuItem_criarMusica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_criarMusicaActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem_criarMusica);

        jMenuItem_analisarMusica.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\modoAnalisarCerto.png")); // NOI18N
        jMenuItem_analisarMusica.setText("Analyzer music");
        jMenuItem_analisarMusica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_analisarMusicaActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem_analisarMusica);
        jMenu1.add(jSeparator1);

        jMenuItem_sair.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\fechar.png")); // NOI18N
        jMenuItem_sair.setText("Exit");
        jMenuItem_sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_sairActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem_sair);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Help");

        jMenuItem_help.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\help.png")); // NOI18N
        jMenuItem_help.setText("Help");
        jMenu2.add(jMenuItem_help);

        jMenuItem2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Lucas Ismaily\\Documents\\NetBeansProjects\\TCC-2\\Icones\\about.png")); // NOI18N
        jMenuItem2.setText("About");
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed


        jTextArea_result.setText(null);


    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed



        try {
            player = MidiSystem.getSequencer();
            player.open();

            if (musicMidi == null) {

                jTextArea_result.append("Error: Please, choose first the MIDI file \n");
                return;
            }
            player.setSequence(musicMidi);
            player.start();


        } catch (MidiUnavailableException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidMidiDataException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        // Abre o sequenciador



        // Seta a música que queremos tocar nos equenciador






    }//GEN-LAST:event_jButton2ActionPerformed

    private void jMenuItem_abrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_abrirActionPerformed
        jTextArea_result.setText(null);
        FileDialog fd = new FileDialog(new Frame(), "Open MIDI file or choose cancel to" + " finish.", FileDialog.LOAD);
        fd.setVisible(true);
        if (fd != null) {
            try {
                File url = new File(fd.getDirectory() + "\\" + fd.getFile());
                musicMidi = MidiSystem.getSequence(url);
                score = new Score();

                Read.midi(score, fd.getDirectory() + fd.getFile());
                score.setTitle(fd.getFile());
                Synthesizer synthesizer = MidiSystem.getSynthesizer();
                if (synthesizer != null) {
                    synthesizer.open();
                    //todos os instrumentos possível da tecnologia MIDI
                    Instrument instrumentosPossiveis[] = synthesizer.getAvailableInstruments();
                    //todos os instrumentos da música selecionada
                    ArrayList<Integer> instrumentosDaMusica = UtilQMusic.getInstrumetsJmusic(score);
                    instruments = UtilQMusic.getInstrumetsMusica(instrumentosPossiveis, instrumentosDaMusica);
                    UtilQMusic.getNotesByInstrumetAndFile(url, 0);
                    if (instruments == null) {
                        jTextArea_result.append("Format error: corrupt MIDI file\n");
                    } else {
                        jComboBox_instrument.removeAllItems();
                        for (Instrument instr : instruments) {
                            jComboBox_instrument.addItem(instr.getName());
                        }

                        float tam = url.length() / (float) 1024;
                        DecimalFormat df = new DecimalFormat();
                        df.setMaximumFractionDigits(3);
                        df.setMinimumFractionDigits(1);
                        df.format(tam);
                        jLabel_dadosArquivo.setText("File name: " + url.getName() + " size: " + (df.format(tam)) + " Kb");
                        jLabel_dadosArquivo.setForeground(Color.BLUE);
                        setEscolhaDisponivel(true);
                        iniTiposReconhecimento();
                        file = url;
                        jTextArea_result.append("file uploaded successfully\n");
                    }

                } else {
                    jTextArea_result.append("Format error: corrupt MIDI file\n");
                }
            } catch (InvalidMidiDataException ex) {
                jTextArea_result.setText(null);
                jTextArea_result.append("Format error: Please, check format chosen\n");
                System.out.println(ex.getMessage());
            } catch (MidiUnavailableException ex) {
                jTextArea_result.setText(null);
                jTextArea_result.append("Format error: Please, check format chosen\n");
                System.out.println(ex.getMessage());
            } catch (IOException ex) {
                jTextArea_result.setText(null);
                jTextArea_result.append("Format error: Please, check format chosen\n");
                System.out.println(ex.getMessage());
            }
        }
    }//GEN-LAST:event_jMenuItem_abrirActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenuItem_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_sairActionPerformed


        System.exit(0);

    }//GEN-LAST:event_jMenuItem_sairActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed



        instrumentoSelecionado = UtilQMusic.getInstrumetByName(instruments, jComboBox_instrument.getSelectedItem().toString());
        if (instrumentoSelecionado == null) {
            jTextArea_result.append("Error: check your choices options\n");
            return;
        }
        if (setNotes()) {
            List<Nota> notas = UtilQMusic.ConvertNotasToNotacaCompleta(notes);
            if (notas == null || notas.isEmpty()) {
                jTextArea_result.append("Error: no notes \n");
                return;
            }
            int cont = 1;
            jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
            jTextArea_result.append("[Option: List Notes ]\n");
            jTextArea_result.append("[chosen music has " + notas.size() + " note(s) ] \n");
            jTextArea_result.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
            //jTextArea_result.append("[" + cont + "] ");
            for (int i = 0; i < notas.size(); i++) {
               
                jTextArea_result.append(" " + notas.get(i).getNota());
                 if (i % 25 == 0 && i != 0) {
                    jTextArea_result.append("\n");
                    //jTextArea_result.append("[" + (++cont) + "] ");
                }
            }
        } else {
            jTextArea_result.append("Error: no notes \n");
        }








    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

        if (player == null) {
            jTextArea_result.append("Error: Please, choose first the MIDI file \n");
            return;
        }
        player.stop();








    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton_noteAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteAActionPerformed

        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }

        Nota n = new Nota(Note.A);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");


    }//GEN-LAST:event_jButton_noteAActionPerformed

    private void jButton_noteBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteBActionPerformed


        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.B);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");
    }//GEN-LAST:event_jButton_noteBActionPerformed

    private void jButton_noteCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteCActionPerformed


        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.C);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");
    }//GEN-LAST:event_jButton_noteCActionPerformed

    private void jButton_noteDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteDActionPerformed


        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.D);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");
    }//GEN-LAST:event_jButton_noteDActionPerformed

    private void jButton_noteEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteEActionPerformed

        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.E);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");


    }//GEN-LAST:event_jButton_noteEActionPerformed

    private void jButton_noteFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteFActionPerformed


        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.F);
        notes.add(n);

        jTextArea_notes.append(n.getNota() + " ");

    }//GEN-LAST:event_jButton_noteFActionPerformed

    private void jButton_noteGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_noteGActionPerformed


        if (notes == null || notes.isEmpty()) {
            notes = new ArrayList<Nota>();
        }
        Nota n = new Nota(Note.G);
        notes.add(n);
        double a = SB;
        jTextArea_notes.append(n.getNota() + " ");



    }//GEN-LAST:event_jButton_noteGActionPerformed

    private void jButton_acidenteSustenidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_acidenteSustenidoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_acidenteSustenidoActionPerformed

    private void jButton_acidenteBemolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_acidenteBemolActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_acidenteBemolActionPerformed

    private void jMenuItem_criarMusicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_criarMusicaActionPerformed

        jPanel_AnalisarMusica.setVisible(false);
        jPanel_CriarMusica.setVisible(true);

    }//GEN-LAST:event_jMenuItem_criarMusicaActionPerformed

    private void jMenuItem_analisarMusicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_analisarMusicaActionPerformed


        jPanel_AnalisarMusica.setVisible(true);
        jPanel_CriarMusica.setVisible(false);





    }//GEN-LAST:event_jMenuItem_analisarMusicaActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed



        Phrase f = new Phrase();
        Part p = new Part(f);
        Score ss = new Score(p);
        Write.midi(ss, "teste.mid");







    }//GEN-LAST:event_jButton6ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jButton_deteleNotesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_deteleNotesActionPerformed

        if (notes != null && !notes.isEmpty()) {
            notes.remove(notes.size() - 1);
            jTextArea_notes.setText(null);
            for (int i = 0; i < notes.size(); i++) {
                if (i % 100 == 0 && i > 0) {
                    jTextArea_notes.append("\n");
                }
                jTextArea_notes.append(notes.get(i).getNota() + " ");
            }
        } else {
            jTextArea_notes.append("No notes\n");
        }



    }//GEN-LAST:event_jButton_deteleNotesActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton4ActionPerformed

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton5ActionPerformed

    private void jComboBox_tipoEscolhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_tipoEscolhaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox_tipoEscolhaActionPerformed

    private void jRadioButton_modo_padraoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton_modo_padraoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton_modo_padraoActionPerformed

    private void jButton_reconhecerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_reconhecerActionPerformed

        String tipoReconhecimento = null;
        jTextArea_result.setText(null);
        //verificar se tem notas, ou seja, algum arquivo midi instrumentoSelecionado com notas


        instrumentoSelecionado = UtilQMusic.getInstrumetByName(instruments, jComboBox_instrument.getSelectedItem().toString());
        if (instrumentoSelecionado == null) {
            jTextArea_result.append("Error: check your choices options\n");
            return;
        }
        setNotes();
        if (notes == null || notes.isEmpty()) {
            jTextArea_result.append("no Notes\n");
        } else {
            //verificar o tipo de modo para exibir - Modo padrão, avançado e mostrar tudo
            if (jRadioButton_modo_avancado.isSelected()) {
                tipoReconhecimento = Properties.RECONHECER_MODO_AVANCADO;
            } else if (jRadioButton_modo_padrao.isSelected()) {
                tipoReconhecimento = Properties.RECONHECER_MODO_PADRAO;
            } else if (jRadioButton_mostrar_todas_notas.isSelected()) {
                tipoReconhecimento = Properties.RECONHECER_MODO_EXIBIR_TUDO;
            }
            //Se nenhum modo foi instrumentoSelecionado, exibe msg de erro e acaba o metodo
            if (tipoReconhecimento == null) {
                jTextArea_result.append("Error: check your choices options\n");
                return;
            }

            //escolher os tipos de reconhecimento, de acordo com o que foi marcado na tela -> opçao de reconher 
            //(Tríade e Tetrades) e modo de visualizaçao -> padrão, avançado e tudo
            if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TODAS_TETRADES)) {
                //setEscolhaDisponivel(false);
                reconherTodasTetrades(Properties.RECONHECER_TODAS_TETRADES, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TODAS_TRIADES)) {
                //setEscolhaDisponivel(false);
                reconherTodasTriades(Properties.RECONHECER_TODAS_TRIADES, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TRIADES_TETRADES)) {
                //setEscolhaDisponivel(false);
                reconhecerTriadesTetrades(Properties.RECONHECER_TRIADES_TETRADES, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TRIADES_AUMENTADA)) {
                //setEscolhaDisponivel(false);
                reconherTriades(Properties.TRIADE_AUMENTADA, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TRIADES_DIMINUTA)) {
                //setEscolhaDisponivel(false);
                reconherTriades(Properties.TRIADE_DIMINUTA, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TRIADES_MAIORES)) {
                //setEscolhaDisponivel(false);
                reconherTriades(Properties.TRIADE_MAIOR, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_TRIADES_MENORES)) {
                //setEscolhaDisponivel(false);
                reconherTriades(Properties.TRIADE_MENOR, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_APENAS_TETRADES_MAIORES)) {
                //setEscolhaDisponivel(false);
                reconherTetrades(Properties.RECONHECER_APENAS_TETRADES_MAIORES, tipoReconhecimento);
            } else if (jComboBox_tipoEscolha.getSelectedItem().toString().equals(Properties.RECONHECER_APENAS_TETRADES_MENORES)) {
                //setEscolhaDisponivel(false);
                reconherTetrades(Properties.RECONHECER_APENAS_TETRADES_MENORES, tipoReconhecimento);
            } else {
                jTextArea_result.append("Error: option of recognize was chosen wrong \n");
            }
        }


    }//GEN-LAST:event_jButton_reconhecerActionPerformed

    private void jRadioButton_mostrar_todas_notasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton_mostrar_todas_notasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton_mostrar_todas_notasActionPerformed

    public void paint(Graphics g) {  
       BufferedImage img = null;           
        try {
            img = ImageIO.read(new File("Icones/play.png"));
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        Graphics2D g2d = (Graphics2D) g.create();         
        g2d.drawImage(img, 100, 100, null);  
        g.dispose();  
                  
    } 
    public void gXYZ() throws IOException    
        {  
            BufferedImage img = ImageIO.read(new File("Icones/play.png"));                  
            paint(img.createGraphics());
       /*     
        BufferedImage img = ImageIO.read(new File("Icones/play.png"));           
        Graphics2D g = img.createGraphics();    
        Graphics2D g2d = (Graphics2D) g.create();         
        g2d.drawImage(img, 100, 100, null);  
        g.dispose();  
        g.drawLine(50, 25, 30, 40);          
         */       
                
              
        } 
    
    
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {                        
            gXYZ();
            //BufferedImage imagem = ImageIO.read(new File("Icones\\play.png"));           
            //JOptionPane.showMessageDialog(null, imagem);
            
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GrupoBotoesDetalhamento;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton_acidenteBemol;
    private javax.swing.JButton jButton_acidenteSustenido;
    private javax.swing.JButton jButton_deteleNotes;
    private javax.swing.JButton jButton_noteA;
    private javax.swing.JButton jButton_noteB;
    private javax.swing.JButton jButton_noteC;
    private javax.swing.JButton jButton_noteD;
    private javax.swing.JButton jButton_noteE;
    private javax.swing.JButton jButton_noteF;
    private javax.swing.JButton jButton_noteG;
    private javax.swing.JButton jButton_reconhecer;
    private javax.swing.JComboBox jComboBox_instrument;
    private javax.swing.JComboBox jComboBox_tipoEscolha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel_dadosArquivo;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem_abrir;
    private javax.swing.JMenuItem jMenuItem_analisarMusica;
    private javax.swing.JMenuItem jMenuItem_criarMusica;
    private javax.swing.JMenuItem jMenuItem_help;
    private javax.swing.JMenuItem jMenuItem_sair;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel_AnalisarMusica;
    private javax.swing.JPanel jPanel_CriarMusica;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton_modo_avancado;
    private javax.swing.JRadioButton jRadioButton_modo_padrao;
    private javax.swing.JRadioButton jRadioButton_mostrar_todas_notas;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JTextArea jTextArea_notes;
    private javax.swing.JTextArea jTextArea_result;
    // End of variables declaration//GEN-END:variables
}
